/**
 * @Author ZhangCuirong
 * @Date 2025/9/5 8:05
 * @description:
 */
public class Solution162 {
    public int findPeakElement(int[] nums) {
        if (nums == null || nums.length == 0) {
            return -1;
        }
        if (nums.length == 1) {
            return 0;
        }
        int left = 0, right = nums.length - 1;
        while (left < right) {
            int mid = (left + right) / 2;
            if (nums[mid] > nums[mid + 1]) {//走势下行
                right = mid;
            } else if (nums[mid] < nums[mid + 1]) {//走势上行
                left = mid + 1;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        Solution162 solution = new Solution162();
        System.out.println(solution.findPeakElement(new int[]{1, 2, 3, 1}));
        System.out.println(solution.findPeakElement(new int[]{1, 2, 1, 3, 5, 6, 4}));
    }
}
